package per.destiny.seckill.service;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import per.destiny.seckill.mapper.SeckillOrderMapper;
import per.destiny.seckill.pojo.SeckillOrder;
import per.destiny.seckill.pojo.SeckillOrderExample;

import java.util.List;

@Service
public class SeckillOrderService {

    @Autowired
    private SeckillOrderMapper seckillOrderMapper;

    public SeckillOrder getOne(Long userId, Long goodsId) {
        SeckillOrderExample seckillOrderExample = new SeckillOrderExample();
        seckillOrderExample.createCriteria().andUserIdEqualTo(userId).andGoodsIdEqualTo(goodsId);
        List<SeckillOrder> seckillOrders = seckillOrderMapper.selectByExample(seckillOrderExample);
        if (CollectionUtils.isEmpty(seckillOrders)) {
            return null;
        }
        return seckillOrders.get(0);
    }
}
